/**   
* @Title: printPaymentDetail.java 
* @Package print 
* @Description: 
* Copyright: Copyright (c) 2014 
* Company:wuwh team by iss
* @author: ScreenJxp   
* @date: 2014年11月27日 上午11:48:26 
* @version: V1.0
*
*/
package com.kerrykidz.system.util.printReceipt;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.util.Date;
import java.util.List;

public class printPaymentDetail  extends PrintBase {
	
	public printPaymentDetail(List<PrinterMessage> list) {
		super(list);
		this.list=list;
	}
	public int print(Graphics gra, PageFormat pf, int pageIndex)
			throws PrinterException {
		System.out.println(list);
		try {
			/**
			 * * @param Graphic指明打印的图形环境 * @param
			 * PageFormat指明打印页格式（页面大小以点为计量单位，1
			 * 点为1英寸的1/72，1英寸为25.4毫米。A4纸大致为595×842点） * @param pageIndex指明页号
			 **/
			// 转换成Graphics2D
			Graphics2D g2_1 = (Graphics2D) gra;
			// Graphics2D g2_2 = (Graphics2D) gra;
			// 设置打印颜色为黑色
			g2_1.setColor(Color.black);
			//g2_1.set
			// g2_2.setColor(Color.black);
			// 打印起点坐标
			switch (pageIndex) {
			case 0:
				// 设置打印字体（字体名称、样式和点大小）（字体名称可以是物理或者逻辑名称）
				// Java平台所定义的五种字体系列：Serif、SansSerif、Monospaced、Dialog 和
				// DialogInput
				Font fontBrand = new Font("宋体", Font.PLAIN, 10);
				Font font = new Font("宋体", Font.BOLD, 6);
				Font font2 = new Font("宋体", Font.PLAIN,6);
				g2_1.setFont(font2); // 设置字体
				// BasicStroke bs_3=new BasicStroke(0.5f);
				float[] dash1 = { 2.0f };
				// 设置打印线的属性。
				// 1.线宽 2端点的装饰、3应用在路径线段交汇处的装饰，4、空白的宽度，5、虚线的宽度，6、偏移量
				g2_1.setStroke(new BasicStroke(0.5f, BasicStroke.CAP_BUTT,
						BasicStroke.JOIN_MITER, 2.0f, dash1, 0.0f));
				double x = pf.getImageableX()/2;
				double y = pf.getImageableY()/2;
				float heigth = font2.getSize2D() + 2; // 字体高度
				PrinterMessage bean = list.get(0);
				// 打印菜单头部信息
				g2_1.setFont(fontBrand); // 设置字体
				g2_1.drawString("收银明细", (float) x + 7, (float)y+20);
				y+=2;
				g2_1.drawLine((int)x+5, (int) (y+5 + 3 * heigth),
				(int) x + 200, (int) (y + 5+3 * heigth));
				x+=10;
				g2_1.setFont(font2);
				g2_1.drawString("现金金额：", (float) x + 20, (int) (y-2+5*heigth));
				g2_1.drawString(bean.getAdmin(), (float) x + 100, (int) (y-2 + 5* heigth));
				y+=10;
				g2_1.setFont(font2); // 设置字体
				g2_1.drawString("刷卡金额：", (float) x + 20,
						(float) y + 5 * heigth);
				g2_1.drawString(bean.getBrand(), (float) x + 100,
						(float) y + 5 * heigth);
				y+=10;
				
				g2_1.drawString("储值消费金额：", (float) x + 4, (int) (y +   5*heigth));
				g2_1.drawString(bean.getCash(), (float) x + 100, (int) (y +   5*heigth));
				y+=10;
				g2_1.drawString("今日累计收入：", (float) x + 4,(int) (y +   5*heigth));
				g2_1.drawString(bean.getCashier(), (float) x + 100, (int) (y +  5* heigth));
				x-=10;
				g2_1.drawString("日期：", (float) x, (int) (y + 20+ 5* heigth));
				g2_1.drawString(formatDateTime(new Date()), (float) x + 30,  (int) (y+20 +  5* heigth));
				y+=10;
				g2_1.drawString("", (float) x+5, (int) (y +20+  5* heigth));
				y+=10;
				g2_1.drawString("", (float) x+5, (int) (y +20+  5* heigth));
				y+=10;
				g2_1.drawString("", (float) x+5, (int) (y +20+  5* heigth));
				y+=10;
				g2_1.drawString("", (float) x+5, (int) (y +20+  5* heigth));
				y+=10;
				g2_1.drawString("'", (float) x+5, (int) (y +20+  5* heigth));
			
				return PAGE_EXISTS;
			default:
				return NO_SUCH_PAGE;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}


}
